package cn.tb.ymcc.service.impl;

import cn.tb.ymcc.domain.BlacklistSms;
import cn.tb.ymcc.domain.MessageSms;
import cn.tb.ymcc.dto.BlackListDto;
import cn.tb.ymcc.mapper.BlacklistSmsMapper;
import cn.tb.ymcc.service.IBlacklistSmsService;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author tangbo
 * @since 2022-07-19
 */
@Service
public class BlacklistSmsServiceImpl extends ServiceImpl<BlacklistSmsMapper, BlacklistSms> implements IBlacklistSmsService {
    @Autowired
    private BlacklistSmsMapper blacklistSmsMapper;
    @Autowired
    private MessageSmsServiceImpl messageSmsService;
    @Override
    public BlacklistSms loadByMobile(String mobile) {
        return blacklistSmsMapper.loadByMobile(mobile);
    }

    /**
     * 移除黑名单
     * @param id
     */
    @Override
    public void removeBlackList(BlackListDto dto) {
        MessageSms messageSms = messageSmsService.selectByMobile(dto.getMobile());
        messageSms.setState(0);
        EntityWrapper<MessageSms> wrapper = new EntityWrapper();
        Wrapper<MessageSms> smsWrapper = wrapper.eq("id", messageSms.getId());
        messageSmsService.update(messageSms,smsWrapper);
        blacklistSmsMapper.removeBlackList(dto.getId());

    }

}
